const { sys_form_field, sys_form, op } = require("../../middleware/baseModel");
const { getMd5 } = require("../../tool/funTool");

module.exports = {
  "GET /sys_form_field/all": async (ctx, next) => {
    let form_id = ctx.get("form_id");
    const resList = await sys_form_field.findAll({
      where: { form_id },
      include: [
        {
          association: sys_form_field.associations.field,
          attributes: ["key", "name"],
        },
      ],
      order: [["sort", "asc"]],
    });
    return ctx.success(resList);
  },

  "POST /sys_form_field/add": async (ctx, next) => {
    let row = ctx.getBody();

    const res = await sys_form_field.create(row);
    return ctx.success(res);
  },
  "POST /sys_form_field/edit": async (ctx, next) => {
    let row = ctx.getBody();
    let { id } = row;

    const res = await sys_form_field.update(row, {
      where: {
        id: id,
      },
    });
    return ctx.success(res);
  },
  "POST /sys_form_field/del": async (ctx, next) => {
    let id = ctx.get("id");
    const res = await sys_form_field.destroy({
      where: {
        id: id,
      },
    });
    return ctx.success(res);
  },
};
